<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <script src="js/react.js"></script>
    <script src="js/react-dom.js"></script>
    <script src="js/browser.min.js"></script>
    <script></script>
</head>
<body>
    <div id='example'></div>

    <script type="text/babel">
        var TestComponent = React.createClass({
            getInitialState:function(){
                return {
                    count:1
                }
            },
            handleClick:function(){
                this.setState({count:2});
            },
            render:function(){
                this.setState({count:2});
                return <div>
                        <h1>这是父组件</h1>
                        <button onClick={this.handleClick}>
                            父组件按钮
                        </button>
                        <MyComponent myCount={this.state.count}>
                        </MyComponent>
                    </div>
            }
        });

        var MyComponent = React.createClass({
            componentWillUpdate:function(){
                console.log('子组件的update钩子函数被执行了');
            },
            handleClick:function(){
                //尝试：修改props对象中的值
                this.props.myCount = 100;
            },
            render:function(){
                return <div>
                    <h3>这是子组件</h3>  
                    <button onClick={this.handleClick}>
                        子组件按钮
                    </button>
                </div>
            }
        });

        ReactDOM.render(
            <TestComponent></TestComponent>,
            document.getElementById('example')
        );
    </script>
</body>
</html>